var dataApi = require("../../provider/dataApi.js"), globalData = (require("../../provider/pipe.js"), 
getApp());

Page({
    data: {
        statusBarHeight: "",
        titleBarHeight: "",
        windowHeight: 0,
        knowledgeList: [],
        knowledgeIndex: 0,
        payOpen: "",
        title: "",
        isBool: !0,
        isLoading: !0,
        userInfo: {}
    },
    onLoad: function(params) {
        wx.getStorageSync("uid") ? (windowHeight = wx.getSystemInfoSync().windowHeight, this.setData({
            statusBarHeight: getApp().globalData.statusBarHeight,
            titleBarHeight: getApp().globalData.titleBarHeight,
            windowHeight: windowHeight,
            title: globalData.title
        })) : wx.navigateTo({
            url: "/pages/login/login"
        });
    },
    goBack: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    onReady: function() {},
    getUserInfo: function() {
        var self = this;
        dataApi.userinfo({
            uid: wx.getStorageSync("uid"),
            op: "getinfo"
        }).then(function(response) {
            console.log(response);
            self.setData({
                userInfo: response.data.info
            });
        }).catch(function(error) {
            console.log(error);
        });
    },
    onShow: function() {
        this.getUserInfo();
        this.fetchKnowledge();
    },
    fetchKnowledge: function() {
        var self = this;
        dataApi.knowledge({
            op: "cate",
            type: globalData.type,
            uid: wx.getStorageSync("uid")
        }).then(function(response) {
            console.log(response);
            var hasKnowledge = !1;
            0 < response.data.list.length && (hasKnowledge = !0), self.setData({
                knowledgeList: response.data.list,
                payOpen: response.data.pay_open,
                isBool: hasKnowledge,
                isLoading: !1
            });
        }).catch(function(error) {
            console.log(error);
        });
    },
    ltChoose: function(event) {
        this.setData({
            knowledgeIndex: event.currentTarget.dataset.index
        });
    },
    rtChoose: function(event) {
        var chapterId = event.currentTarget.dataset.chapterId;
        var fatherIsCan = event.currentTarget.dataset.fatherIsCan;

        console.log(event);
        event = event.currentTarget.dataset.item;
        this.setData({
            item: event
        });
        event.fatherIsCan = fatherIsCan;
        debugger
        event.chapterId = chapterId;
        self.globalData.oItem = event;
        wx.navigateTo({
            url: "../knowledgePoints-list/knowledgePoints-list"
        });
    },
    closePayPopup: function() {
        this.setData({
            showPay: !1
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});